package cn.hsa.xxx.imgFsStore.controller;

import cn.hsa.hsaf.core.framework.web.WrapperResponse;
import cn.hsa.xxx.api.service.BookInfoService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/web/imgFsStore/imgStorage")
@RestController
@Slf4j
@Api(tags = "封面管理")
public class ImgStorageController {

    @Autowired
    private BookInfoService bookInfoService;

    @PutMapping("/setCoverImg")
    public WrapperResponse<String> toSetCoverImg(MultipartFile file, String bookUuid) {
        bookInfoService.addCoverImg(file, bookUuid);
        return WrapperResponse.success("设置成功");
    }

    @GetMapping("/getCoverImgUrl")
    public WrapperResponse<String> toGetCoverImgUrl(String bookUuid) {
        String imgUrl = bookInfoService.getCoverImgUrl(bookUuid);
        return WrapperResponse.success(imgUrl);
    }

    @PutMapping("/deleteCoverImg")
    public WrapperResponse<String> toDeleteCoverImg(String bookUuid) {
        String result = bookInfoService.deleteCoverImg(bookUuid);
        return WrapperResponse.success(result);
    }
}
